package models

import "log"

//登陆逻辑判断
func Login(info *User) error{
	err := dbc.Read(info, "Username","Password")
	return err
}

//注册逻辑判断
func Register(info *User) error {
	_,err := dbc.Insert(info)
	return err
}

// 返回所有用户列表
func GetAllUserList() []User {
	data := []User{}
	err := dbx.Select(&data, "select * from user")
	if err != nil {
		panic(err.Error())
	}
	return data
}

// 返回所有群组列表
func GetAllGroupList() []Groups {
	data := []Groups{}
	err := dbx.Select(&data, "select * from groups")
	if err != nil {
		log.Println(err.Error())
	}
	return data
}

// 返回个人用户信息
func GetPersionInfo(username string) User {
	data := User{Username:username}
	err := dbc.Read(&data,"Username")
	if err != nil {
		panic(err.Error())
	}
	return data
}

// 修改签名
func ModifySign(username,sign string) error{
	user := GetPersionInfo(username)
	user = User{Id:user.Id,Sign:sign}
	_,err := dbc.Update(&user,"sign")
	return err
}